package org.sunshine.miracle.web.gwt.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.rpc.RemoteService;

import java.util.List;
import java.io.File;

/**
 * User: djiva
 * Date: Dec 10, 2008
 * Time: 2:15:40 PM
 */
public interface FileService extends RemoteService {

    /**
     * Returns the children of the given parent.
     *
     * @param folder the parent folder
     * @return the children
     */
    public List<FileModel> getFolderChildren(FileModel folder);

    public static class ServiceLoader {
        public static final String SERVICE_LOCATION = GWT.getModuleBaseURL() + "/fileservice";
        private static FileServiceAsync ourInstance = null;

        public static synchronized FileServiceAsync getInstance() {
            if (ourInstance == null) {
                ourInstance = (FileServiceAsync) GWT.create(FileService.class);
                ((ServiceDefTarget) ourInstance).setServiceEntryPoint(SERVICE_LOCATION);
            }
            return ourInstance;
        }
    }
}
